home *** CD-ROM | disk | FTP | other *** search
- Path: dawn.mmm.com!news
- From: kjhopps@mmm.com (Kevin J Hopps)
- Newsgroups: comp.lang.c++
- Subject: Re: Mutexes make const functions impossible!?
- Date: 4 Mar 1996 14:57:01 GMT
- Organization: 3M - St. Paul, MN 55144-1000 US
- Message-ID: <4hf0bt$69q@dawn.mmm.com>
- References: <825596770.4813@redifon.demon.co.uk>
- Reply-To: kjhopps@mmm.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Guy Pickering (gp@redifon.demon.co.uk) wrote:
- > Usually, my classes have a number of const functions for getting internal
- > data (e.g. getWidth(), getNumEvents()). My problem is that when I wish
- > to be thread-safe, I need to lock and unlock a mutex every time I access
- > internal data. This means my functions can no longer be const because the
- > mutex member is being locked and unlocked.
-
- > Is this a situation where the const'ness should be cast away, or am I
- > dammed to throw away all const'ness from thread-safe functions. Or is
- > there another solution?
-
- You can make the mutex member mutable. If your compiler does not support
- "mutable," this situation justifies casting away const.
- --
- Kevin J. Hopps e-mail: kjhopps@mmm.com
- 3M Company phone: (612) 737-4643
- 3M Center, Bldg. 235-2D-57 fax: (612) 737-2700
- St. Paul, MN 55144-1000 Opinions are my own. I don't speak for 3M.
- But 3M speaks for me -- I did not write the following line:
-
- Opinions expressed herein are my own and may not represent those of 3M.
-